#include <iostream>
#include <vector>
using namespace std;
vector<vector<int> > res;

void backtrack(int nums[], int len, vector<int> &track)
{

    //路径：记录在track中
    //选择列表：nums中不存在于track中的元素
    //结束条件：nums中元素全部都在track中出现；
    if (track.size() == len)
    {
        vector<int> temp(track);
        res.push_back(temp);
        return;
    }

    for(int i = 0; i < len; i++)
    {   
        //判断nums[i]是否在track中，如果在，那么continue
        bool flag = false;
        for(unsigned int j = 0; j < track.size(); j++)
        {
            if(track[j] == nums[i])
            {
                flag = true;
                break;
            }
        }
        if (flag) continue;

        //做选择
        track.push_back(nums[i]);
        //回调回溯函数
        backtrack(nums, len, track);
        //撤销选择
        track.pop_back();

    }
}
int main()
{
    using namespace std;
    int nums [3] = {1, 2, 3};
    vector<int> track;
    backtrack(nums, 3, track);
    for(unsigned int i = 0; i < res.size(); i++)
    {
        for(unsigned int j = 0; j < res[i].size(); j++)
        {
            cout << res[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}